package cn.edu.neu.vmmigeval.evaluation;

import cn.edu.neu.vmmigeval.cloud.entity.Host;

import java.util.List;

/**
 * Created by yfwz100 on 16/2/25.
 */
public class SLAViolation {

    public int getSLAViolations(List<Host> hosts) {
        int num = 0;
        for (Host host : hosts) {
            double bwUtilization = (double) host.getCurrentBw() / host.getTotalBw();
            double cpuUtilization = (double) host.getCurrentCpu() / host.getTotalCpu();
            double ramUtilization = (double) host.getCurrentRam() / host.getTotalRam();
            if (bwUtilization >= 0.99 || cpuUtilization >= 0.99 || ramUtilization >= 0.99 ||
                    (bwUtilization >= 0.9 && cpuUtilization >= 0.9 && ramUtilization >= 0.9)) {
                num++;
            }
        }
        return num;
    }
}
